"""
系统管理相关的数据库实体模型
"""
from datetime import datetime
from enum import Enum
from typing import Optional

from pydantic import BaseModel, ConfigDict


class PermissionType(str, Enum):
	MENU = "MENU"
	API = "API"
	BUTTON = "BUTTON"
	DATA = "DATA"


class RoleType(str, Enum):
	SYSTEM = "SYSTEM"
	CUSTOM = "CUSTOM"


class Role(BaseModel):
	id: int
	role_code: str
	role_name: str
	description: Optional[str] = None
	type: RoleType = RoleType.CUSTOM
	enabled: bool = True
	deleted: bool = False
	version: int = 1
	gmt_create: datetime
	gmt_update: datetime

	model_config = ConfigDict(from_attributes=True)


class Permission(BaseModel):
	id: int
	perm_code: str
	perm_name: str
	type: PermissionType = PermissionType.API
	parent_id: int = 0
	path: Optional[str] = None
	level: int = 1
	sort: int = 0
	deleted: bool = False
	gmt_create: datetime

	model_config = ConfigDict(from_attributes=True)


class UserRole(BaseModel):
	user_id: int
	role_id: int

	model_config = ConfigDict(from_attributes=True)


class RolePermission(BaseModel):
	role_id: int
	perm_id: int

	model_config = ConfigDict(from_attributes=True)


class AuditLog(BaseModel):
	id: int
	user_id: Optional[str] = None
	action: str
	target_type: str
	target_id: str
	request_ip: str
	request_uri: str
	result: bool = True
	gmt_create: datetime

	model_config = ConfigDict(from_attributes=True)
